@extends('admin.layout')
@section('title','商品统计')
@section('body')

    <div id="search" style="height:63px;">
        <blockquote class="layui-elem-quote" style="font-size: 14px">
            <form action="" method="get" class="layui-form">
                <div class="layui-form-item">
                    <div  class="layui-inline">
                        <label class="layui-form-label">搜索</label>
                        <div class="layui-input-inline">
                            <input type="tel" id="" name="keywords"  lay-verify="required" placeholder="请输入商品名称" autocomplete="off" class="layui-input ">
                        </div>
                    </div>
                    {{csrf_field()}}
                    <div class="layui-inline">
                        <input  type="submit" class="layui-btn layui-btn-small" value="搜索">
                    </div>
                    <div class="layui-inline">
                        共有{{$goods_sum}}个种类商品,其中上架状态{{$up_goods}}个。总库存:{{$stock}},总销量{{$sell}}。
                    </div>
                </div>
            </form>
        </blockquote>
    </div>
    <div id="search" style="height:63px;">
        <blockquote class="layui-elem-quote" style="font-size: 14px">
            <form action="" method="post" class="layui-form">
               <input type="button" class="btn btn-success" onclick="window.location.href='{{url('count/goods')}}?sell=desc'" value="按销量从高到低">
               <input type="button" class="btn btn-success" onclick="window.location.href='{{url('count/goods')}}?sell=asc'" value="按销量从低到高">
               <input type="button" class="btn btn-primary" onclick="window.location.href='{{url('count/goods')}}?stock=desc'" value="按库存从高到低">
               <input type="button" class="btn btn-primary" onclick="window.location.href='{{url('count/goods')}}?stock=asc'" value="按库存从低到高">
                <div class="layui-input-inline">
                    <select name="classify_id" lay-filter="classify">
                        <option value="0" @if($selected==0) selected @endif>按分类筛选</option>
                     @foreach($arr as $value)
                            <option @if($selected==$value['classify_id']) selected @endif value="{{$value['classify_id']}}"> @if($value['level']==1) {{$value['name']}} @else &nbsp;&nbsp;&nbsp;--{{$value['name']}} @endif</option>
                     @endforeach
                    </select>
                </div>

            </form>

        </blockquote>

    </div>
    <table class="layui-table " >
        <colgroup>
        </colgroup>
        <thead>
        <tr>
            <th>品名</th>
            <th>封面</th>
            <th>价格</th>
            <th>商品编号</th>
            <th>更新时间</th>
            <th>库存</th>
            <th>销量</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        @foreach($goods as $value)
            <tr class=" bg-warning ">
                <td>{{$value->name}}</td>
                <td><img style="width: 80px;height: 80px" src="{{url($value->my_cover)}}" alt=""></td>
                <td>{{$value->price}}</td>
                <td>{{$value->goods_sn}}</td>
                <td>{{$value->updated_at}}</td>
                <td>{{$value->stock}}</td>
                <td>{{$value->sell}}</td>
                <td>
                    <button  class="btn btn-primary"  onclick="stock({{$value->goods_id}})">加库存</button>
                </td>
            </tr>

        @endforeach
        </tbody>
    </table>
    {!! $goods->links() !!}
@endsection
@section('js')
    <script>
        @if(Session::has('message'))
            layer.msg("{{Session::get("message")}}");
        {{Session::forget('message')}}
        @endif

        layui.use(["form",'layer'],function () {
            var form = layui.form();
            form.on('select(classify)',function (data) {
                window.location.href="{{url('count/goods')}}?classify="+data.value;
            });
        });

        function stock(id) {
            layer.open({
                title:"增加库存",
                content:'<form id="stock" method="post" >{{csrf_field()}}<input type="hidden" name="goods_id" value="'+id+'"><input type="number" class="form-control" placeholder="增加库存" name="stock" value="1"></form>',
                yes:function () {
                    $("#stock").submit();
                }
            });
        }


    </script>
@endsection